package com.sky.controller.admin;

import com.sky.dto.EmployeeDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrdersAdminService;
import com.sky.service.OrdersService;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/order")
@Slf4j
@Api(tags = "套餐管理接口")
public class OrdersAdminController {
    @Autowired
    OrdersService ordersService;
    @Autowired
    OrdersAdminService ordersAdminService;

    @PutMapping("/complete/{id}")
    public Result complete(@PathVariable Long id) {
        log.info("选择完成的订单编号:" + id);
        ordersService.complete(id);
        return Result.success();
    }

    /**
     * 查询订单详情
     *
     * @param id
     * @return
     */
    @GetMapping("/details/{id}")
    public Result<OrderVO> findById(@PathVariable Long id) {
        log.info("查询详情的订单id:" + id);
        OrderVO orderVO = ordersService.findById(id);
        return Result.success(orderVO);
    }


    /**
     * <<<<<<< HEAD
     * 派送订单
     *
     * @param id
     * @return
     */
    @PutMapping("delivery/{id}")
    @ApiOperation("派送订单")
    public Result delivery(@PathVariable Long id) {
        ordersService.delivery(id);
        return Result.success();
    }
    @GetMapping("/conditionSearch")
    public Result<PageResult> page(OrdersPageQueryDTO ordersPageQueryDTO){
        PageResult pageResult = ordersAdminService.page(ordersPageQueryDTO);
        return Result.success(pageResult);
    }
//    @GetMapping("/statistics")
//    public Result statistics(Integer statistics){
//        System.out.println(statistics);
//        return Result.success();
//    }

    /**
     * 商家接单
     * @param ordersRejectionDTO
     * @return
     */
    @ApiOperation("商家接单")
    @PutMapping("/confirm")
    public Result updateConfirm(@RequestBody OrdersRejectionDTO ordersRejectionDTO) {
        ordersService.updateConfirm(ordersRejectionDTO.getId());
        return Result.success("接单成功");
    }

    /**
     * 商家拒单
     * @param ordersRejectionDTO
     * @return
     */
    @ApiOperation("商家拒单")
    @PutMapping("/rejection")
    public Result updateRejection(@RequestBody OrdersRejectionDTO ordersRejectionDTO) {
        ordersService.updateRejection(ordersRejectionDTO);
        return Result.success("拒单成功");
    }
}
